$(document).ready($(function() {
	support.defaultDate("startTime","endTime");
	pagingQuery(1, paging.defaultPageSize);
	paging.queryFunc = pagingQuery;
	queryClick();
	initBankInfo();
}));

var query = {};
function pagingQuery(pageIndex, pageSize) {

	query.pageIndex = pageIndex;
	query.pageSize = pageSize;
	support.ajax("bankCard/queryCard", query, function(data) {
		var datalist = data.respInfo.cardList.dataList;
		if (datalist.length) {
			$('#nodata').hide();
			$('#cardInfo').html($('#cardListInfo').render(datalist));
			$('#pagingContainer').show();
			paging.doPaging("pagingContainer", data.respInfo.cardList);
		} else {
			$('#pagingContainer').hide();
			$('#cardInfo').empty();
			$('#nodata').show();
		}
	}, function(data) {
		showMsg("N", "操作失败！");
	});
}

function btnQuery(pageIndex, pageSize) {

	query.pageIndex = pageIndex;
	query.pageSize = pageSize;
	
	if ($("#cusCode").val()) {
		query.cusCode = $("#cusCode").val();
	} else {
		query.cusCode = null;
	}
	if ($("#userName").val()) {
		query.userName = $("#userName").val();
	} else {
		query.userName = null;
	}
	if ($("#realName").val()) {
		query.realName = $("#realName").val();
	} else {
		query.realName = null;
	}
	if ($("#cusIdNum").val()) {
		query.cusIdNum = $("#cusIdNum").val();
	} else {
		query.cusIdNum = null;
	}
	if ($("#cardNum").val()) {
		query.cardNum = $("#cardNum").val();
	} else {
		query.cardNum = null;
	}
	if ($("#cusMobile").val()) {
		query.cusMobile = $("#cusMobile").val();
	} else {
		query.cusMobile = null;
	}
	if ($("#bankName").val()) {
		query.bankName = $("#bankName").val();
	} else {
		query.bankName = null;
	}
	if ($(".start_time").val()) {
		query.startTime = $(".start_time").val();
	}
	if ($(".end_time").val()) {
		query.endTime = $(".end_time").val();
	}
	
	pagingQuery(pageIndex, pageSize);
}

function queryClick() {
	$('#query').live("click", function() {
		btnQuery(1, paging.defaultPageSize);
	});
}

function showMsg(objResult, msg) {
	$('#sperr').html(msg);
	if (objResult == "Y") {
		$('#LoginError').hide();
	} else {
		$('#LoginError').show();
		$('#pagingContainer').hide();
		$('#cardInfo').empty();
	}
}

function initBankInfo(){
	var qk={};
	qk.trdCode="CO";
	support.ajax("sysbank/selectBankDataList", qk, function(data) {
		var dataList = data.respInfo.sysbanklist;
		$("#chiceBank").html(
				"<option value=''>------请选择------</option>"
						+ $("#bankListJs").render(dataList));
	});	
}


function upCard(data){
	$(".wrong").hide();
	$('#failedMassge').val('');	
	$('#bankNum').val('');	
	$('#chiceBank').val('');
	support.ajax("bankCard/queryById", data, function(data) {
		var info = data.respInfo.card;	
		$('#cardId').val(info.cardId);
		$('#userNameInfo').html(info.userName);
		$('#realNameInfo').html(info.realName);
		$('#idNum').html(info.cusIdNum);
		$('#bankCode').html(info.cardNum);
		$('#mobile').html(info.cusMobile);
		$('#bank').html(info.bankName);
		$('#bindTime').html(info.preTime);
		//$('#failedMassge').val(info.failedMsg);	
		$('#shade01').show();
		$('#mask_window01').show();
	});	
}

function hiddenDiv(){
	$('#shade01').hide();
	$('#mask_window01').hide();	
}

function resetQuery(){
	$("#bkForm")[0].reset();  
	support.defaultTime("startTime","endTime");
}

function changeCard(){
	// 将参数封装成json格式
	var param = {};
	param.cardNum = $("#bankNum").val();
	param.bankCode = $("#chiceBank").val();
	param.cardId = $("#cardId").val();
	param.failedMsg = $("#failedMassge").val();
	
	support.ajax("bankCard/changeBank", param, function(data) {
		alert('换绑成功');
		location.reload(true);
	});
	return false;
}

function checkBank(){
	var param= {};
	if(null!=$('#chiceBank').val() && ""!=$('#chiceBank').val()){
		param.branchName=$("#chiceBank")[0].options[$("#chiceBank")[0].selectedIndex].text;
	}
	var cardNum=$("#bankNum").val();
	if(cardNum){
		param.cardNum=cardNum;
	}
	var succ = false;
	support.syncAjax("bankCard/checkBank", param, function(data) {
		var isValid = data.respInfo.isValid;
		if (isValid == "Y") {
			succ = true;
		}else{
			succ = false;
		}
	});
	return succ;
}